import { Injectable } from '@angular/core';
import { Title } from '@angular/platform-browser';

@Injectable()
export class DocumentTileService {


    constructor(private title: Title) { }

    setTitle(title) {
        this.title.setTitle(title);
        this.updateDocumentTile(title);
    }

    private updateDocumentTile(title) {
        const body = $('body');
        document.title = title;

        const iframe = $('<iframe src="/favicon.ico" style="display: none"></iframe>');
        iframe.on('load', function () {
            setTimeout(function () {
                iframe.off('load').remove();
            }, 0);
        }).appendTo(body);
    }

}
